package 每日一题;

public class 最长回文串 {
    static String res="";
    public static String longestPalindrome(String s) {
        for (int i=0;i<s.length();i++){
            //奇数情况
            String res1=leng(s,i,i);
            //偶数情况
            String res2=leng(s,i,i+1);
            res=res.length()>res1.length()?res:res1;
            res=res.length()>res2.length()?res:res2;
        }
        return res;
    }
    static String leng(String s,int i,int j){
        while (i>=0&&j<s.length()&&s.charAt(i)==s.charAt(j)){
            i--;
            j++;
        }
        return s.substring(i+1,j);
    }
    public static void main(String[] args) {
        System.out.println("longestPalindrome(\"aaaaaaabbbbbbbbbaaaaaaaa\") = " + longestPalindrome("aaaaaaabbbbbbbbbaaaaaaaa"));
    }
}
